package com.bstek.uflo.samplecenter;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bstek.uflo.model.ProcessInstance;
import com.bstek.uflo.model.task.Task;
import com.bstek.uflo.service.ProcessService;
import com.bstek.uflo.service.StartProcessInfo;
import com.bstek.uflo.service.TaskService;

@Controller
public class TestCirculation {
	//开启一个流程
	//完成任务并指定传阅人
	//任务处理人完成任务，传阅人不完成
	//任务处理人完成，传阅人填写意见
	@Resource(name=TaskService.BEAN_ID)
	private TaskService taskService;
	@Resource(name=ProcessService.BEAN_ID)
	private ProcessService processService;
	@RequestMapping("/appointCirc")
	@ResponseBody
	public void appointCirc(@RequestParam Map<String,Object>params) {
		Long processId=Long.parseLong((String)params.get("processId"));
		StartProcessInfo st= new StartProcessInfo("user1");
//		st.setCompleteStartTask(false);
		ProcessInstance pi=processService.startProcessById(processId, st);
		List<Task>list=taskService.createTaskQuery().processInstanceId(pi.getId()).nodeName(pi.getCurrentNode()).list();
		String targetUrl="http://baidu.com";
		Long taskId=null;//Long.parseLong((String)params.get("taskId"));
		taskId=list.get(0).getId();
		String taskNodeName=(String) params.get("tNodeName");
		taskNodeName="人工任务2";
//		taskNodeName=pi.getCurrentNode();
		taskService.saveTaskPasserby(taskId, targetUrl, "user1", taskNodeName);
	}
}
